package com.twu.driver;

import com.twu.biblioteca.Library;
import com.twu.biblioteca.Movie;
import com.twu.io.IOHandler;

import java.util.ArrayList;

/**
 * Created by vishwasdamle on 10/08/14.
 */
public class MovieOperations {
    private Library library;
    private IOHandler io;

    public MovieOperations(Library library) {
        this.library = library;
        io = new IOHandler();
    }

    public void returnMovies() {
        io.displayString("Enter Movie name to return : ");
        try {
            library.returnMovie(io.getString());
            io.displayString("Successful Return : Thank you for returning the Movie");
        } catch (Exception e) {
            io.displayString("Unsuccessful Return : That is not a valid Movie to return.");
        }
    }

    public void checkOutMovies() {
        displayAvailableMovies();
        io.displayString("Enter Movie name to check out : ");
        try {
            library.checkOutMovie(io.getString());
            io.displayString("Successful Checkout : Thank you! Enjoy the Movie!");
        } catch (Exception e) {
            io.displayString("Unsuccessful Checkout : That Movie is not available.");
        }
    }

    public void displayAvailableMovies() {
        ArrayList<Movie> availableMovieList = library.getAvailableMovieList();
        for(Movie movie : availableMovieList) {
            io.displayString("\t: " + movie.toString());
        }
    }

}
